const path = require("path");
const packageName = require('./package.json').name;
const publicPath = process.env.VUE_APP_PUBLIC_PATH;
const port = process.env.PORT;

module.exports = {
  publicPath: publicPath,
  lintOnSave: false,
  devServer: {
    // 监听端口
    port: port,
    // 关闭主机检查，使微应用可以被 fetch
    disableHostCheck: true,
    // 配置跨域请求头，解决开发环境的跨域问题
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    overlay: {
        warning: false,
        errors: false
    }
  },
  chainWebpack: (config) => {
    const fontRule = config.module.rule('fonts');
    fontRule.uses.clear();
    fontRule
      .use('file-loader')
      .loader('file-loader')
      .options({
        name: 'fonts/[name].[hash:8].[ext]',
        publicPath
      })
      .end()
    const imgRule = config.module.rule('images');
    imgRule.uses.clear();
    imgRule
      .use('file-loader')
      .loader('file-loader')
      .options({
        name: 'imgs/[name].[hash:8].[ext]',
        publicPath
      })
      .end()
  },
  productionSourceMap: false, // 设置为false浏览器控制台Sources中webpack//显示源码
  configureWebpack(config) {  // 正常是对项目运行进行判断是否开启sourceMap,这里一刀切了
      config.devtool = false;
  },
  configureWebpack: {
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
    output: {
      // 微应用的包名，这里与主应用中注册的微应用名称一致
      library: `${packageName}-[name]`,
      // 将你的 library 暴露为所有的模块定义下都可运行的方式
      libraryTarget: "umd",
      // 按需加载相关，设置为 webpackJsonp_VueMicroApp 即可
      jsonpFunction: `webpackJsonp_${packageName}`,
    },
  },
};